//// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//package com.linqingying.gitcode.pullrequest.ui.filters
//
//import com.intellij.collaboration.ui.codereview.avatar.Avatar
//import com.intellij.collaboration.ui.codereview.list.search.ChooserPopupUtil
//import com.intellij.collaboration.ui.codereview.list.search.DropDownComponentFactory
//import com.intellij.collaboration.ui.codereview.list.search.ReviewListSearchPanelFactory
//import com.intellij.collaboration.ui.util.popup.PopupItemPresentation
//import kotlinx.coroutines.CoroutineScope
//import kotlinx.coroutines.flow.flow
//import org.jetbrains.annotations.Nls
//import com.linqingying.gitcode.i18n.GitCodeBundle
//import com.linqingying.gitcode.ui.avatars.GCAvatarIconsProvider
//import javax.swing.JComponent
//
//internal class GCPRSearchPanelFactory(vm: GCPRSearchPanelViewModel, private val avatarIconsProvider: GCAvatarIconsProvider) :
//  ReviewListSearchPanelFactory<GCPRListSearchValue, GCPRListQuickFilter, GCPRSearchPanelViewModel>(vm) {
//
//  override fun getShortText(searchValue: GCPRListSearchValue): @Nls String = with(searchValue) {
//    @Suppress("HardCodedStringLiteral")
//    StringBuilder().apply {
//      if (searchQuery != null) append(""""$searchQuery"""").append(" ")
//      if (state != null) append("""state:"${getShortText(state)}"""").append(" ")
//      if (label != null) append("label:$label").append(" ")
//      if (assignee != null) append("assignee:$assignee").append(" ")
//      if (reviewState != null) append("""reviewState:"${getShortText(reviewState)}"""").append(" ")
//      if (author != null) append("author:$author").append(" ")
//    }.toString()
//  }
//
//  override fun createFilters(viewScope: CoroutineScope): List<JComponent> = listOf(
//    DropDownComponentFactory(vm.stateFilterState)
//      .create(viewScope,
//              filterName = GitCodeBundle.message("pull.request.list.filter.state"),
//              items = GCPRListSearchValue.State.values().asList(),
//              onSelect = {},
//              valuePresenter = Companion::getShortText),
//    DropDownComponentFactory(vm.authorFilterState)
//      .create(viewScope, GitCodeBundle.message("pull.request.list.filter.author")) { point ->
//        ChooserPopupUtil.showAsyncChooserPopup(
//          point,
//          itemsLoader = flow { emit(runCatching { vm.getAuthors() }) },
//          presenter = {
//            PopupItemPresentation.Simple(
//              it.shortName,
//              avatarIconsProvider.getIcon(it.avatarUrl, Avatar.Sizes.BASE),
//              it.name?.let { fullName -> "(${fullName})" })
//          }
//        )?.login
//      },
//    DropDownComponentFactory(vm.labelFilterState)
//      .create(viewScope, GitCodeBundle.message("pull.request.list.filter.label")) { point ->
//        ChooserPopupUtil.showAsyncChooserPopup(
//          point,
//          itemsLoader = flow { emit(runCatching { vm.getLabels() }) },
//          presenter = { PopupItemPresentation.Simple(it.name) }
//        )?.name
//      },
//    DropDownComponentFactory(vm.assigneeFilterState)
//      .create(viewScope, GitCodeBundle.message("pull.request.list.filter.assignee")) { point ->
//        ChooserPopupUtil.showAsyncChooserPopup(
//          point,
//          itemsLoader = flow { emit(runCatching { vm.getAssignees() }) },
//          presenter = {
//            PopupItemPresentation.Simple(
//              it.shortName,
//              avatarIconsProvider.getIcon(it.avatarUrl, Avatar.Sizes.BASE),
//              it.name?.let { fullName -> "($fullName)" })
//          }
//        )?.login
//      },
//    DropDownComponentFactory(vm.reviewFilterState)
//      .create(viewScope,
//              filterName = GitCodeBundle.message("pull.request.list.filter.review"),
//              items = GCPRListSearchValue.ReviewState.values().asList(),
//              onSelect = {},
//              valuePresenter = Companion::getShortText,
//              popupItemPresenter = { PopupItemPresentation.Simple(getFullText(it)) })
//  )
//
//  override fun GCPRListQuickFilter.getQuickFilterTitle(): String = when (this) {
//    is GCPRListQuickFilter.Open -> GitCodeBundle.message("pull.request.list.filter.quick.open")
//    is GCPRListQuickFilter.YourPullRequests -> GitCodeBundle.message("pull.request.list.filter.quick.yours")
//    is GCPRListQuickFilter.AssignedToYou -> GitCodeBundle.message("pull.request.list.filter.quick.assigned")
//    is GCPRListQuickFilter.ReviewRequests -> GitCodeBundle.message("pull.request.list.filter.quick.review.requests")
//  }
//
//  companion object {
//    private fun getShortText(stateFilterValue: GCPRListSearchValue.State): @Nls String = when (stateFilterValue) {
//      GCPRListSearchValue.State.OPEN -> GitCodeBundle.message("pull.request.list.filter.state.open")
//      GCPRListSearchValue.State.CLOSED -> GitCodeBundle.message("pull.request.list.filter.state.closed")
//      GCPRListSearchValue.State.MERGED -> GitCodeBundle.message("pull.request.list.filter.state.merged")
//    }
//
//    private fun getShortText(reviewStateFilterValue: GCPRListSearchValue.ReviewState): @Nls String = when (reviewStateFilterValue) {
//      GCPRListSearchValue.ReviewState.NO_REVIEW -> GitCodeBundle.message("pull.request.list.filter.review.no.short")
//      GCPRListSearchValue.ReviewState.REQUIRED -> GitCodeBundle.message("pull.request.list.filter.review.required.short")
//      GCPRListSearchValue.ReviewState.APPROVED -> GitCodeBundle.message("pull.request.list.filter.review.approved.short")
//      GCPRListSearchValue.ReviewState.CHANGES_REQUESTED -> GitCodeBundle.message("pull.request.list.filter.review.change.requested.short")
//      GCPRListSearchValue.ReviewState.REVIEWED_BY_ME -> GitCodeBundle.message("pull.request.list.filter.review.reviewed.short")
//      GCPRListSearchValue.ReviewState.NOT_REVIEWED_BY_ME -> GitCodeBundle.message("pull.request.list.filter.review.not.short")
//      GCPRListSearchValue.ReviewState.AWAITING_REVIEW -> GitCodeBundle.message("pull.request.list.filter.review.awaiting.short")
//    }
//
//    private fun getFullText(reviewStateFilterValue: GCPRListSearchValue.ReviewState): @Nls String = when (reviewStateFilterValue) {
//      GCPRListSearchValue.ReviewState.NO_REVIEW -> GitCodeBundle.message("pull.request.list.filter.review.no.full")
//      GCPRListSearchValue.ReviewState.REQUIRED -> GitCodeBundle.message("pull.request.list.filter.review.required.full")
//      GCPRListSearchValue.ReviewState.APPROVED -> GitCodeBundle.message("pull.request.list.filter.review.approved.full")
//      GCPRListSearchValue.ReviewState.CHANGES_REQUESTED -> GitCodeBundle.message("pull.request.list.filter.review.change.requested.full")
//      GCPRListSearchValue.ReviewState.REVIEWED_BY_ME -> GitCodeBundle.message("pull.request.list.filter.review.reviewed.full")
//      GCPRListSearchValue.ReviewState.NOT_REVIEWED_BY_ME -> GitCodeBundle.message("pull.request.list.filter.review.not.full")
//      GCPRListSearchValue.ReviewState.AWAITING_REVIEW -> GitCodeBundle.message("pull.request.list.filter.review.awaiting.full")
//    }
//  }
//}
